package com.openass.math
{
   
   /**
    * A random uint generator.
    * </br></br>
    * <code>
    * var seed:Array = UniqRand.getUintSeed(0, 100, 5);</br>
    * </code>
    * @author boy, cjboy1984@gmail.com
    * @date 2012/05/05
    */
   public class UniqRand
   {
      
      public function UniqRand()
      {
      }
      
      // ________________________________________________
      //                                         function
      
      /**
       * Randomly create "uint" array and all the values are unique. Example:
       * </br>
       * <code>
       * var seed:Array = UniqRand.getUintSeed(0, 100, 5);</br>
       * trace(seed); // [15, 23, 1, 87, 65]
       * </code>
       * @param min     Minimum value.
       * @param max     Maximum value.
       * @param count   Total count of the array.
       * @return        <code>Array</code>
       */
      public static function getUintSeed(min:uint, max:uint, count:uint):Array
      {
         var range:uint = max - min;
         var count_x2:uint = count<<1;
         var ret:Array = [];
         while (ret.length < count)
         {
            var v:uint = min + Math.round(range * Math.random());
            if (range >= count_x2)
            {
               if (ret.indexOf(v) == -1)
               {
                  ret.push(v);
               }
            }
            else
            {
               ret.push(v);
            }
         }
         return ret;
      }
      
      // ################### protected ##################
      
      // #################### private ###################
      
      // --------------------- LINE ---------------------
      
   }
   
}